//配置
//词频统计
// allPosBar();

/**
 * 展示词频
 * @param table
 */
function allPosBar(data) {

    var table = data.data;

    //词性表，存储出现过的词性
    var posSet = new Set();
    //词性对应的名称表
    var posNameArr = new Array();
    //词性对应的词表
    var posMap = new Map();
    //词性对应的频率表
    var posFrequencyMap = new Map();


    //词性分类
    for (var i = 0; i < table.length; i++) {
        posSet.add(table[i].pos);
    }
    //新建数组
    for (var i = 0; i < posSet.size; i++) {
        var arr = new Array();
        posMap.set(Array.from(posSet)[i], arr);
        // posNameArr.push(getPosLevel_1((Array.from(posSet)[i])));
    }
    //词按词性分类
    for (var i = 0; i < table.length; i++) {
        posMap.get(table[i].pos).push(table[i]);
    }
    //取出table中的数据,目前我需要统计的就是这些名词、动词、形容词、时间词
    posMap.forEach(function (value, key, map) {
        var count = 0;
        for (var i = 0; i < value.length; i++) {
            count += value[i].count;
        }
        posFrequencyMap.set(key, value.length);

    });

    /********************     数据分类结束   ************************/

        //统计第一组数据,标题
    var legendData = posNameArr;

    //第二组数组，按词性大体的数据对比
    var posData = new Array();
    var posRecord = new Array();
    //第三组数据，展示每个词性的前几个词汇
    var outPieArr = new Array();
    var showN = 10;

    posFrequencyMap.forEach(function (value, key, map) {

        var obj = new Object();
        obj.name = getPosLevel_1(key);
        obj.value = value;
        obj.selected = false;
        posData.push(obj);

        //辅助判断的，这里写得太乱了
        var newObj = new Object();
        newObj.name = key;
        newObj.value = value;
        posRecord.push(newObj);

    });
    //按频率排序
    posData.sort(sortByFrequenct);
    posRecord.sort(sortByFrequenct);
    if (posData.length > 3) {
        //截取数组的前4位
        if (posData.length > 3) {
            posData = posData.slice(0, 4);
            //将其他的数据设置为其他
            var obj = new Object();
            obj.name = "其它";
            obj.value = table.length - posData[0].value - posData[1].value - posData[2].value - posData[3].value;
            obj.selected = true;
            posData.push(obj);
            for (var i = 0; i < 4; i++) {
                posNameArr.push(getPosLevel_1(posRecord[i].name));
            }
            posNameArr.push("其它");

        }

        for (var i = 0; i < 4; i++) {
            //按照上面已经拍过顺序的词性来取出对应的词的列表
            var words = posMap.get(posRecord[i].name);
            var front_4 = words.slice(0, words.length / showN + 1);
            var others = words.slice(words.length / showN + 1, words.length - 1);
            //展示1/3比例的名词
            for (var j = 0; j < front_4.length; j++) {
                var tempObj = new Object();
                tempObj.name = front_4[j].name + "（" + getPosLevel_1(posRecord[i].name) + "）";
                tempObj.value = front_4[j].count;
                outPieArr.push(tempObj);
            }
            //统计剩下2/3占的比例
            var othersCount = 0;
            for (var j = 0; j < others.length; j++) {
                othersCount += others[j].count;
            }
            var tempObj = new Object();
            tempObj.name = '其它' + getPosLevel_1(posRecord[i].name);
            tempObj.value = othersCount;
            outPieArr.push(tempObj);

        }
        var tempObj = new Object();
        tempObj.name = '其它词性';
        tempObj.value = posData[posData.length - 1].value;
        outPieArr.push(tempObj);
    }
    //如果词性不够三个的话
    else {
        for (var i = 0; i < posData.length; i++) {
            posNameArr.push(getPosLevel_1(posRecord[i].name));
            //按照上面已经拍过顺序的词性来取出对应的词的列表
            var words = posMap.get(posRecord[i].name);
            var front_4 = words.slice(0, words.length / showN + 1);
            var others = words.slice(words.length / showN + 1, words.length - 1);
            //展示1/3比例的名词
            for (var j = 0; j < front_4.length; j++) {
                var tempObj = new Object();
                tempObj.name = front_4[j].name + "（" + getPosLevel_1(posRecord[i].name) + "）";
                tempObj.value = front_4[j].count;
                outPieArr.push(tempObj);
            }
            //统计剩下2/3占的比例
            var othersCount = 0;
            for (var j = 0; j < others.length; j++) {
                othersCount += others[j].count;
            }
            var tempObj = new Object();
            tempObj.name = '其它' + getPosLevel_1(posRecord[i].name);
            tempObj.value = othersCount;
            outPieArr.push(tempObj);
        }

    }


    /**饼图部分**/
        // 基于准备好的dom，初始化echarts实例， 第一个饼状图完成
    var myChart = echarts.init(document.getElementById('div_all_pos_graph'), 'macarons');
    myChart.title = '词性-词频饼状图';
    var option = {
        toolbox: {
            show: true,
            feature: {
                dataZoom: {
                    yAxisIndex: 'none'
                },
                dataView: {readOnly: false},
                magicType: {type: ['line', 'bar']},
                restore: {},
                saveAsImage: {}
            }
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            x: 'left',
            data: posNameArr
        },
        series: [
            {

                name: '词汇频率',
                type: 'pie',
                selectedMode: 'single',
                radius: [0, '30%'],
                // minAngle: 20,

                label: {
                    normal: {
                        position: 'inner'
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data: posData
            },
            {
                name: '词汇',
                type: 'pie',
                radius: ['40%', '55%'],
                label: {
                    normal: {
                        formatter: '{a|{a}}{abg|}\n{hr|}\n  {b|{b}：}{c}  {per|{d}%}  ',
                        backgroundColor: '#eee',
                        borderColor: '#aaa',
                        borderWidth: 1,
                        borderRadius: 4,
                        shadowBlur: 3,
                        shadowOffsetX: 2,
                        shadowOffsetY: 2,
                        shadowColor: '#999',
                        padding: [0, 7],
                        rich: {
                            a: {
                                color: '#999',
                                lineHeight: 22,
                                align: 'center'
                            },
                            // abg: {
                            //     backgroundColor: '#333',
                            //     width: '100%',
                            //     align: 'right',
                            //     height: 22,
                            //     borderRadius: [4, 4, 0, 0]
                            // },
                            hr: {
                                borderColor: '#aaa',
                                width: '100%',
                                borderWidth: 0.5,
                                height: 0
                            },
                            b: {
                                fontSize: 16,
                                lineHeight: 33
                            },
                            per: {
                                color: '#eee',
                                backgroundColor: '#334455',
                                padding: [2, 4],
                                borderRadius: 2
                            }
                        }
                    }
                },
                data: outPieArr
            }
        ]
    };
    myChart.setOption(option);

    /**条形图部分**/
        //第一个条形图
    var showM = 15;
    var verb = new Object();
    verb.title = '动词词频统计';
    verb.legend = new Array().push('词频');
    verb.verbGroup = getWordsFrequencyNameArr(posMap, 'v', showM);
    verb.series = getWordsFrequencyCountArr(posMap, 'v', showM, 'bar');
    verb.theme = 'infographic';
    frequencyBar('div_verb_pos_graph', verb);

    //第二个条形图
    var non = new Object();
    non.title = '名词词频统计';
    non.legend = new Array().push('词频');
    non.verbGroup = getWordsFrequencyNameArr(posMap, 'n', showM);
    non.series = getWordsFrequencyCountArr(posMap, 'n', showM, 'bar');
    non.theme = 'roma';
    frequencyBar('div_non_pos_graph', non);

    //第三个条形图
    var adj = new Object();
    adj.title = '形容词词频统计';
    adj.legend = new Array().push('词频');
    adj.verbGroup = getWordsFrequencyNameArr(posMap, 'a', showM);
    adj.series = getWordsFrequencyCountArr(posMap, 'a', showM, 'bar');
    adj.theme = 'shine';
    frequencyBar('div_adj_pos_graph', adj);

    /**
     * 填充条形图的Y轴数据
     * @param posMap
     * @param posEngName
     * @param N
     * @returns {any[]}
     */
    function getWordsFrequencyNameArr(posMap, posEngName, N) {

        var words = posMap.get(posEngName);
        var nameArr = new Array();
        if (words.length > N) {
            // nameArr.push('其它') + getPosLevel_1(posEngName);
            for (var i = 0; i < N; i++) {
                nameArr.push(words[i].name);
            }
            return nameArr;
        }
        else {
            for (var i = 0; i < words.length; i++) {
                nameArr.push(words[i].name);
            }
            return nameArr;
        }

    }

    /**
     * 填充条形图X轴的数据
     * @param posMap
     * @param posEngName
     * @param N
     */
    function getWordsFrequencyCountArr(posMap, posEngName, N, type) {

        var series = new Object();
        var countArr = new Array();
        series.name = getPosLevel_1(posEngName);
        series.type = type;
        series.data = countArr;

        var words = posMap.get(posEngName);

        if (words.length > N) {
            var front = words.slice(0, N);
            var others = words.slice(N, words.length - 1);
            // var othersCount = 0;
            // for (var i = 0; i < others.length; i++) {
            //     othersCount += others[i].count;
            // }
            // countArr.push(othersCount);
            for (var i = 0; i < N; i++) {
                countArr.push(front[i].count);
            }

        }
        else {
            for (var i = 0; i < words.length; i++) {
                countArr.push(words[i].count);
            }
        }
        return series;

    }
}


/**
 * 动词bar图
 * @param divName
 * @param chartOption
 */
function frequencyBar(divName, chartOption) {

    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById(divName), chartOption.theme);
    myChart.title = chartOption.title;


    myChart.title = chartOption.title + ' - 条形图';

    var option = {
        title: {
            text: chartOption.title,
            subtext: '数据已过滤停用词'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        toolbox: {
            show: true,
            feature: {
                dataView: {readOnly: false},
                magicType: {type: ['line', 'bar', 'pie']},
                restore: {},
                saveAsImage: {}
            }
        },
        legend: {
            data: chartOption.legend
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'value',
            boundaryGap: [0, 0.01]
        },
        yAxis: {
            type: 'category',
            data: chartOption.verbGroup
        },
        series: chartOption.series
    };

    myChart.setOption(option);

}


/**
 * 抽取命名实体的力图
 * @param data
 */
var namedEntityChart;

function namedEntityForceLayout(data) {


    var table = data.data;

    //统计有多少个词性
    var posSet = new Set();
    //图的标题项
    var legend = new Array();
    var legend_arr = new Array();
    for (var i = 0; i < table.length; i++) {
        posSet.add(table[i].pos);
    }
    for (var i = 0; i < posSet.size; i++) {
        legend.push(getPosLevel_2(Array.from(posSet)[i]));

        var obj = new Object();
        obj.name = (getPosLevel_2(Array.from(posSet)[i]));
        legend_arr.push(obj);
    }
    legend.push("总称");
    legend.push('ROOT')
    var obj = new Object();
    obj.name = '总称';
    legend_arr.push(obj);
    var obj = new Object();
    obj.name = 'ROOT';
    legend_arr.push(obj);

    //图的数据项
    var nodes = new Array();

    for (var i = 0; i < table.length; i++) {

        var node = new Object();
        node.name = table[i].name;
        node.itemStyle = null;
        node.symbolSize = 50;
        node.value = 1;
        node.category = legend.indexOf(getPosLevel_2(table[i].pos));
        // Use random x, y
        node.x = node.y = null;
        node.draggable = true;
        nodes.push(node);

    }

    //为大类添加边
    for (var i = 0; i < legend.length - 2; i++) {
        var node = new Object();
        node.name = legend[i];
        node.itemStyle = null;
        node.symbolSize = 50;
        node.value = 1;
        node.category = legend.indexOf('总称');
        // Use random x, y
        node.x = node.y = null;
        node.draggable = true;
        node.symbol = 'rect';
        nodes.push(node);
    }


    var node = new Object();
    node.name = 'root';
    node.itemStyle = null;
    node.symbolSize = 65;
    node.value = 1;
    node.category = legend.indexOf('ROOT');
    // Use random x, y
    node.x = node.y = null;
    node.draggable = true;
    node.symbol = 'roundRect';
    nodes.push(node);

    //关系描述的数组
    var links = new Array();
    for (var i = 0; i < table.length; i++) {
        var link = new Object();
        link.id = i;
        link.source = i;
        link.target = getPosLevel_2(table[i].pos);
        links.push(link);
    }

    //连结ROOT的边
    for (var i = table.length; i < (table.length + legend.length - 2); i++) {
        var link = new Object();
        link.id = i;
        link.source = i;
        link.target = 'root';
        links.push(link);
    }

    // var link = new Object();
    // links.push(link);


    // 基于准备好的dom，初始化ECharts实例
    if (namedEntityChart != null && namedEntityChart != "" && namedEntityChart != undefined) {
        namedEntityChart.dispose();
    }
    namedEntityChart = echarts.init(document.getElementById('div_named_entity_graph'), 'macarons');
    namedEntityChart.showLoading();

    var categories = legend_arr;
    var option = {
        title: {
            text: '实体抽取-力导向图',
            subtext: '二元以上词组',
            top: 'bottom',
            left: 'right'
        },
        tooltip: {},
        legend: {
            type: 'scroll',
            orient: 'vertical',
            right: 10,
            top: 20,
            bottom: 20,
            data: legend_arr,

            selected: data.selected
        },

        animation: true,
        series: [
            {
                name: '实体',
                type: 'graph',
                layout: 'force',
                data: nodes,
                links: links,
                categories: categories,
                roam: false,
                label: {
                    show: true,
                    position: 'inside'

                },
                force: {
                    repulsion: 400
                }
            }
        ]
    };

    namedEntityChart.setOption(option);
    namedEntityChart.hideLoading();

}

/**
 * 地图可视化
 * @param area
 */
var mapChart;

function mapLayout(area) {
    var listData = area.data;

    //赋值给chart
    var thisChart = mapChart;
    //处理数据
    var copyArr = listData;//浅复制
    var convertData = [];
    var posMap = new Map();
    for (var i = 0; i < listData.length; i++) {
        if (listData[i].pos == "ns") {
            console.log(listData[i].name);
            var obj = new Object();
            obj.name = listData[i].name;
            obj.symbol = 'circle';
            obj.value = undefined;
            CITYMAP.forEach(function (value, key, map) {
                if (key.indexOf(obj.name) != -1) {
                    obj.value = CITYMAP.get(listData[i].name);
                }
            })
            if (obj.value == undefined) {
                continue;
            }
            if (posMap.get(listData[i].name) == undefined) {
                posMap.set(listData[i].name, 1);
                obj.value.push(1);
            }
            else {
                posMap.set(listData[i].name, (posMap.get(listData[i].name) + 1));
                obj.value[2] = (posMap.get(listData[i].name));
            }
            convertData.push(obj);
        }
    }
    console.log(convertData);


    // 基于准备好的dom，初始化ECharts实例
    if (thisChart != null && thisChart != "" && thisChart != undefined) {
        thisChart.dispose();
    }
    thisChart = echarts.init(document.getElementById('div_map_graph'), 'macarons');
    thisChart.showLoading();

    var option = {
        backgroundColor: '#ffffff',
        title: {
            text: "文本地域可视化散点图",
            subtext: '出现频率越高的地名，颜色越深',
            x: 'center',
            textStyle: {
                color: '#111'
            }
        },
        tooltip: {
            trigger: 'item',
            formatter: function (params) {
                return params.name + ' : ' + params.value[2];
            }
        },
        legend: {
            orient: 'vertical',
            y: 'bottom',
            x: 'right',
            data: ['地名'],
            textStyle: {
                color: '#111'
            }
        },
        visualMap: {
            min: 0,
            max: 10,
            calculable: true,
            inRange: {
                color: ['#50a3ba', '#eac736', '#d94e5d']
            },
            textStyle: {
                color: '#111'
            }
        },
        geo: {
            map: 'china',
            // roam: true,
            label: {
                emphasis: {
                    show: false
                }
            },
            itemStyle: {
                normal: {
                    areaColor: '#323c48',
                    borderColor: '#111'
                },
                emphasis: {
                    areaColor: '#111'
                }
            }
        },
        series: [
            {
                name: '地名',
                type: 'scatter',
                roam: true,
                coordinateSystem: 'geo',
                data: convertData,
                symbolSize: 20,
                label: {
                    normal: {
                        show: false
                    },
                    emphasis: {
                        show: false
                    }
                },
                itemStyle: {
                    emphasis: {
                        borderColor: '#111',
                        borderWidth: 1
                    }
                }
            }
        ]

    };
    thisChart.setOption(option);
    thisChart.hideLoading();

}


/**
 * 相似度对比的bar图
 * @param data
 */
var similarChart;

function loadsimilarCompareBar(data) {


    var table = data.data.res;

    var y = new Array();
    var x = new Array();


    // 基于准备好的dom，初始化ECharts实例
    if (similarChart != null && similarChart != "" && similarChart != undefined) {
        similarChart.dispose();
    }
    similarChart = echarts.init(document.getElementById('div_similar_graph'), 'macarons');
    similarChart.showLoading();


    var labelRight = {
        normal: {
            position: 'right'
        }
    };
    for (var i = 0; i < table.length; i++) {
        y.push(table[i].text);

        var xObj = new Object();
        xObj.label = labelRight;
        xObj.value = table[i].cos;
        x.push(xObj);
    }
    var option = {
        title: {
            text: '相似度对比图',
            subtext: '基准文本：最外层的文本框',

        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            top: 80,
            bottom: 30
        },
        xAxis: {
            type: 'value',
            position: 'top',
            splitLine: {lineStyle: {type: 'dashed'}},
            min: -1,
            max: 1,
        },
        yAxis: {
            type: 'category',
            axisLine: {show: false},
            axisLabel: {show: false},
            axisTick: {show: false},
            splitLine: {show: false},
            data: y
        },
        series: [
            {
                name: '相似度',
                type: 'bar',
                stack: '余弦相似度',
                label: {
                    normal: {
                        show: true,
                        formatter: '{b}'
                    }
                },
                data: x
            }
        ]
    };


    similarChart.setOption(option);
    similarChart.hideLoading();

}


/**
 * 载入主题的三个图表
 * @param data
 */
function loadtheme(data) {

    loadThemeRadarData(data);
    themeNormalTheme(data);
    loadThemeDashboadData(data);

}


/**
 * 预测主题的雷达图，累计
 * @param data
 */
var themeRadarChart;

function loadThemeRadarData(data) {

    //赋值给chart
    var thisChart = themeRadarChart;
    //处理数据
    var rank = data.data.rank;

    // 基于准备好的dom，初始化ECharts实例
    if (thisChart != null && thisChart != "" && thisChart != undefined) {
        thisChart.dispose();
    }
    thisChart = echarts.init(document.getElementById('div_radar_graph'), 'macarons');
    thisChart.showLoading();
    var series_data = [];
    var option = {
        title: {
            text: '历史主题模型',
            subtext: '从历史模型数据的变化，提高主题识别的准确度',
            top: 10,
            left: 10
        },
        tooltip: {
            trigger: 'item',
            backgroundColor: 'rgba(0,0,250,0.2)'
        },
        legend: {
            type: 'scroll',
            bottom: 10,
            data: (function () {
                var list = [];
                for (var i = 0; i < rank.length; i++) {
                    list.push(rank[i].date);
                }
                return list;
            })()
        },
        visualMap: {
            top: 'middle',
            right: 10,
            color: ['red', 'blue'],
            calculable: true,
            type: 'continuous',
            min: 0,
            max: 0.9
        },
        radar: {
            indicator: [
                {text: '政治', max: 0.9},
                {text: '军事', max: 0.9},
                {text: '科技', max: 0.9},
                {text: '娱乐', max: 0.9},
                {text: '国际社会', max: 0.9},
                {text: '健康', max: 0.9},
                {text: '图书', max: 0.9},
                {text: '教育', max: 0.9},
                {text: '社会', max: 0.9},
                {text: '电影', max: 0.9},
                {text: '体育', max: 0.9},
                {text: '其他', max: 0.9}
            ]
        },
        series: (function () {
            var series = [];
            for (var i = 0; i < rank.length; i++) {
                series.push({
                    name: rank[i].date,
                    type: 'radar',
                    symbol: 'none',
                    lineStyle: {
                        width: 1
                    },
                    emphasis: {
                        areaStyle: {
                            color: 'rgba(0,250,0,0.3)'
                        }
                    },
                    data: (function () {
                        series_data.push(getData(rank, i));
                        return series_data;
                    })()
                });
            }
            return series;
        })()
    };

    thisChart.hideLoading();
    thisChart.setOption(option);


    //获取series的data部分
    function getData(rank, i) {
        var data = new Object();
        var dataMap = new Map();       //为了我能够按指定顺序排放数据，利用map先把rank的数据存起来，以简直对的形式取出
        var themeDataOrderByLengen = [];
        for (var j = 0; j < rank[i].list.length; j++) {
            dataMap.set(rank[i].list[j].name, rank[i].list[j].p);
        }
        if (dataMap.get("政治") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("政治"));
        if (dataMap.get("军事") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("军事"));
        if (dataMap.get("科技") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("科技"));
        if (dataMap.get("娱乐") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("娱乐"));
        if (dataMap.get("国际") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("国际"));
        if (dataMap.get("健康") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("健康"));
        if (dataMap.get("图书") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("图书"));
        if (dataMap.get("教育") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("教育"));
        if (dataMap.get("社会") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("社会"));
        if (dataMap.get("电影") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("电影"));
        if (dataMap.get("教育") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("教育"));
        if (dataMap.get("其他") == undefined) themeDataOrderByLengen.push(0); else themeDataOrderByLengen.push(dataMap.get("其他"));


        data.name = rank[i].date;
        data.value = themeDataOrderByLengen;


        return data;
    }

}


/**
 * 普通的雷达图
 * @param data
 */
var themeNormalChart;

function themeNormalTheme(data) {
    var thisChart = themeNormalChart;
    var rank = data.data.rank;


    var modelDate = rank[0].date;
    var indicator = new Array();//N边图形
    var eachEdgeData = new Array();//每个边的值的大小
    var serriaData = new Object();
    for (var i = 0; i < rank[0].list.length; i++) {
        var obj = new Object();
        obj.name = rank[0].list[i].name;
        obj.max = 1;
        indicator.push(obj);
        eachEdgeData.push(rank[0].list[i].p);

    }
    serriaData.value = eachEdgeData;
    serriaData.name = "各主题分布概率";


    // 基于准备好的dom，初始化ECharts实例
    if (thisChart != null && thisChart != "" && thisChart != undefined) {
        thisChart.dispose();
    }
    thisChart = echarts.init(document.getElementById('div_nomal_graph'), 'macarons');
    thisChart.showLoading();

    var option = {
        title: {
            text: '主题预测概率雷达图',
            subtext: modelDate
        },
        tooltip: {},
        legend: {
            data: ['主题分布概率']
        },
        radar: {
            // shape: 'circle',
            name: {
                textStyle: {
                    color: '#fff',
                    backgroundColor: '#999',
                    borderRadius: 3,
                    padding: [3, 5]
                }
            },
            indicator: indicator
        },
        series: [{
            name: '主题分布概率-雷达图',
            type: 'radar',
            // areaStyle: {normal: {}},
            data: [
                {
                    value: eachEdgeData
                    , name: "各主题分布概率"
                    , areaStyle: {
                        normal: {
                            opacity: 0.9,
                            color: new echarts.graphic.RadialGradient(0.5, 0.5, 1, [
                                {
                                    color: '#B8D3E4',
                                    offset: 0
                                },
                                {
                                    color: '#72ACD1',
                                    offset: 1
                                }
                            ])
                        }
                    }
                }
            ]
        }]
    };
    thisChart.hideLoading();
    thisChart.setOption(option);

}


/**
 * 这个是仪表盘的图
 * @param data
 */
var themeDashboardChart;

function loadThemeDashboadData(data) {
    //赋值给chart
    var thisChart = themeDashboardChart;
    //处理数据
    var rank = data.data.rank;

    //获取概率最大的主题，以最新的模型来预测
    var themeName = rank[0].list[0].name;
    var numTheme = getPointPos(themeName);

    // 基于准备好的dom，初始化ECharts实例
    if (thisChart != null && thisChart != "" && thisChart != undefined) {
        thisChart.dispose();
    }
    thisChart = echarts.init(document.getElementById('div_Dashboard_graph'), 'macarons');
    thisChart.showLoading();

    var option = {
        tooltip: {
            formatter: "{a} <br/>{b} : {c}%"
        },
        toolbox: {
            feature: {
                restore: {show: true},
                saveAsImage: {show: true}
            }
        },
        series: [
            {
                name: '主题抽取',
                type: 'gauge',
                splitNumber: 11,//分割的段数是十段
                radius: '75%',
                axisLine: {
                    //仪表盘轴线样式
                    lineStyle: {
                        color: [
                            [0, '#001f3f'],
                            [0.09, '#0074D9'],
                            [0.18, '#7FDBFF'],
                            [0.27, '#39CCCC'],
                            [0.36, '#3D9970'],
                            [0.45, '#2ECC40'],
                            [0.54, '#01FF70'],
                            [0.63, '#FFDC00'],
                            [0.72, '#FF851B'],
                            [0.81, '#FF4136'],
                            [0.90, '#85144b'],
                            [1, '#111111']


                        ],
                    }
                },
                title: {
                    // 其余属性默认使用全局文本样式
                    fontWeight: 'bolder',
                    fontSize: 30,
                    fontStyle: 'italic'
                },
                detail: {
                    formatter: function (e) {
                        e = parseInt(e);
                        switch (e + "") {
                            case "0":
                                return "其他"
                            case "9":
                                return "政治";
                            case "18":
                                return "军事";
                            case "27":
                                return "科技";
                            case "36":
                                return "娱乐";
                            case "45":
                                return "国际";
                            case "54":
                                return "健康";
                            case "63":
                                return "体育";
                            case "72":
                                return "社会";
                            case "81":
                                return "电影";
                            case "90":
                                return "教育";
                            case "100":
                                return "图书";

                            default:
                                return "";
                        }
                    },
                    fontWeight: 'bolder',
                    borderRadius:
                        3,
                    backgroundColor:
                        '#444',
                    borderColor:
                        '#aaa',
                    shadowBlur:
                        5,
                    shadowColor:
                        '#333',
                    shadowOffsetX:
                        0,
                    shadowOffsetY:
                        3,
                    borderWidth:
                        2,
                    textBorderColor:
                        '#000',
                    textBorderWidth:
                        2,
                    textShadowBlur:
                        2,
                    textShadowColor:
                        '#fff',
                    textShadowOffsetX:
                        0,
                    textShadowOffsetY:
                        0,
                    fontFamily:
                        'Arial',
                    width:
                        100,
                    color:
                        '#eee',
                    rich:
                        {}
                },
                splitLine:
                    { //分割线样式（及10、20等长线样式）
                        length: 40,
                        lineStyle:
                            { // 属性lineStyle控制线条样式
                                width: 2
                            }
                    }
                ,
                axisTick: { //刻度线样式（及短线样式）
                    length: 20
                }
                ,
                axisLabel: {
                    fontWeight: 'bolder',
                    borderRadius:
                        1,
                    textStyle:
                        {
                            fontSize: 25,
                        }
                    ,
                    textShadowBlur: 1,
                    distance:
                        5,//文字离表盘的距离
                    formatter:

                        function (e) {
                            e = parseInt(e);
                            switch (e + "") {
                                case "0":
                                    return "其他"
                                case "9":
                                    return "政治";
                                case "18":
                                    return "军事";
                                case "27":
                                    return "科技";
                                case "36":
                                    return "娱乐";
                                case "45":
                                    return "国际";
                                case "54":
                                    return "健康";
                                case "63":
                                    return "体育";
                                case "72":
                                    return "社会";
                                case "81":
                                    return "电影";
                                case "90":
                                    return "教育";
                                case "100":
                                    return "图书";

                                default:
                                    return "";
                            }
                        }

                }
                ,
                data: [{value: numTheme, name: '主题提取'}]
            }
        ]
    };


    thisChart.hideLoading();
    thisChart.setOption(option, true);

    /**
     * 获取指针所指位置
     * @param name
     * @returns {number}
     */
    function getPointPos(name) {
        switch (themeName) {
            case "其他":
                return 0;
            case "政治":
                return 9;
            case "军事":
                return 18;
            case "科技":
                return 27;
            case "娱乐":
                return 36;
            case "国际":
                return 45;
            case "健康":
                return 54;
            case "体育":
                return 63;
            case "社会":
                return 72;
            case "电影":
                return 81;
            case "教育":
                return 90;
            case "图书":
                return 100;
            default:
                return 0;
        }
    }


}


/**
 * 这个是情感识别的两个图
 */
var emotionBarChart;
var emotionPieChart;

function loadEmotionGraph(data) {


    loadEmotionBar(data);


    loadEmotionPie(data);

    /**
     * 柱状图
     * @param data
     */
    function loadEmotionBar(data) {
        //赋值给chart
        var thisChart = emotionBarChart;
        //处理数据
        var rank = data.data.rank;

        // 基于准备好的dom，初始化ECharts实例
        if (thisChart != null && thisChart != "" && thisChart != undefined) {
            thisChart.dispose();
        }
        thisChart = echarts.init(document.getElementById('div_emotion_graph'), 'macarons');
        thisChart.showLoading();

        var option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            legend: {
                data: ['正面情绪', '负面情绪']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '70%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'value'
                }
            ],
            yAxis: [
                {
                    type: 'category',
                    axisTick: {show: false},
                    data: ['']
                }
            ],
            series: [
                {
                    name: '正面情绪',
                    type: 'bar',
                    stack: '百分比',
                    label: {
                        normal: {
                            show: true
                        }
                    },
                    data: [320]
                },
                {
                    name: '负面情绪',
                    type: 'bar',
                    stack: '百分比',
                    label: {
                        normal: {
                            show: true,
                            position: 'left'
                        }
                    },
                    data: [-120]
                }
            ]
        };


        thisChart.hideLoading();
        thisChart.setOption(option, true);
    }

    /**
     * 饼图
     * @param data
     */
    function loadEmotionPie(data) {

        //赋值给chart
        var thisChart = emotionPieChart;
        //处理数据
        var res = data.data.res;
        var legend = data.data.catlog;


        for (var i = 0; i < res.length; i++) {

        }

        // 基于准备好的dom，初始化ECharts实例
        if (thisChart != null && thisChart != "" && thisChart != undefined) {
            thisChart.dispose();
        }
        thisChart = echarts.init(document.getElementById('div_emotion_graph'), 'macarons');
        thisChart.showLoading();

        var piePatternSrc = '';


        var piePatternImg = new Image();
        piePatternImg.src = piePatternSrc;
        // var bgPatternImg = new Image();
        // bgPatternImg.src = bgPatternSrc;

        var itemStyle = {
            normal: {
                opacity: 0.7,
                color: {
                    image: piePatternImg,
                    repeat: 'repeat'
                },
                borderWidth: 3,
                borderColor: '#235894'
            }
        };
        var option = {
            title: {
                text: '情感极性图',
                textStyle: {
                    color: '#235894'
                }
            },
            tooltip: {},
            series: [{
                name: '情感极性',
                type: 'pie',
                selectedMode: 'single',
                selectedOffset: 30,
                clockwise: true,
                label: {
                    normal: {
                        textStyle: {
                            fontSize: 18,
                            color: '#235894'
                        }
                    }
                },
                labelLine: {
                    normal: {
                        lineStyle: {
                            color: '#235894'
                        }
                    }
                },
                data: res[0].classify,
                itemStyle: itemStyle
            }]
        };


        thisChart.hideLoading();
        thisChart.setOption(option, true);
    }

}